package com.liangwj.springbootdesignpatterns.createTypePatterns.builder.demo_1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <b>Description:</b> 创建一个 Meal 类，带有上面定义的 Item 对象。 <br/>
 * @author Lingwenjun
 * @date 2019/1/22-16:08
 * @version 1.0
 */
public class FoodMeal {

    private List<FoodItems> foodItems = new ArrayList<>();

    //添加食物条目
    public void addItem(FoodItems item) {
        foodItems.add(item);
    }

    //计算总价
    public BigDecimal getCost() {
        //总价
        BigDecimal cost = BigDecimal.ZERO;
        for (FoodItems items : foodItems) {
            cost = cost.add(items.price());
        }
        return cost;
    }

    //打印单品列表
    public void showFoodItems() {
        foodItems.forEach( (items) -> {
            System.out.print("items = " + items.name());
            System.out.print(", Packing = " + items.packing().pack());
            System.out.println(", price = " + items.price());
        });
    }
}
